home *** CD-ROM | disk | FTP | other *** search
- ; Program: METER.WBT - Author: Richard Merit
- Message("Information","METER.WBT shows how to meter network software Inspect file for more information.")
- exit
-
- ;-----------------------------
- meterdir = "c:\temp" ; Should be the directory on the network drive
- ;-----------------------------
-
-
- meterok = @NO ; Default case is that the app is maxed out
-
- ; Parameter Validation. Needs two or three params
- ; Param1 = Applications Name
- ; Param2 = ADDUSER or REMOVEUSER
- ; Param3 = User Name
- If (param0 < 2) || (param0 > 3) Then Goto parmerror
-
- ;Make sure the meter directory has a whack on the end of it
- If StrSub(meterdir, StrLen(meterdir), 1) != "\" Then meterdir = StrCat(meterdir, "\")
-
- ; Use appname to build app ini file name
- appname = StrUpper(param1)
- inifile = StrUpper("%meterdir%%appname%.ini")
- If FileExist(inifile) == @FALSE Then Goto noini
-
- ; And build a "LockFile" name, used to prevent simultaneous access to the ini file
- lockfile = StrUpper("%meterdir%%appname%.lok")
-
- ; Build username parameter
- username = "UNKNOWN"
- If param0 == 3 Then username = param3
-
- ; So are we adding a user or removing a user
-
- If StriCmp(param2, "ADDUSER") == 0 Then Goto increase
- If StriCmp(param2, "REMOVEUSER") == 0 Then Goto decrease
- Goto parmerror
-
- :increase
- ; Assume responsibility for error handling, and obtain a Lock
- ; on the resources via the LockFile
- ErrorMode(@OFF)
- :iretry
- handle = FileOpen(lockfile, "WRITE") ; Attempt exclusive access at lock
- If LastError() == 1077 then Goto iretry ; Failed? Try again
- ErrorMode(@CANCEL)
-
- ; Get max count
- maxusers = IniReadPvt(appname, "Maximum Users", "", inifile)
- If maxusers == "" Then Goto noini
-
- ; No user counts for unknown users
- if username!="UNKNOWN" then goto checkusage
-
- ; Is a copy already checked out to this user?
- userstatus = IniReadPvt(appname, username, 0, inifile)
- If userstatus > 0 Then Goto allowuser ; Yes, do not increment usage counts
-
- :checkusage
- ; How many people using this now
- currusers = IniReadPvt(appname, "Current Users", 0, inifile)
- If currusers >= maxusers Then Goto userlimit ; Too many users
-
- ; Increment usage count
- IniWritePvt(appname, "Current Users", currusers + 1, inifile)
- ; And remember who is active
- If username != "UNKNOWN" Then IniWritePvt(appname, username, userstatus+1, inifile)
-
- :allowuser
- ; Release Lock
- FileClose(handle)
- ; Return go-ahead signal
- meterok = @YES
- Return
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- :decrease
- ErrorMode(@OFF)
-
- :dretry
- ; Assume responsibility for error handling, and obtain a Lock
- ; on the resources via the LockFile
- ErrorMode(@OFF)
- :iretry
- handle = FileOpen(lockfile, "WRITE") ; Attempt exclusive access at lock
- If LastError() == 1077 then Goto dretry ; Failed? Try again
- ErrorMode(@CANCEL)
-
- ; If no username, just reduce the usage count
- if username=="UNKNOWN" then goto reduceeusage
-
- userstatus = IniReadPvt(appname, username, 1, inifile)
- newstatus=userstatus-1
- if newstatus>=0 then IniWritePvt(appname, username, newstatus, inifile)
-
- if newstatus != 0 then goto dexit
-
- ; Get Count of current users
- :reduceusage
- currusers = IniReadPvt(appname, "Current Users", 0, inifile)
- If currusers > 0 Then IniWritePvt(appname, "Current Users", currusers - 1, inifile)
-
- :dexit
- FileClose(handle)
- Return
-
- :userlimit
- FileClose(handle)
- Return
-
- :parmerror
- Message("METER Error", "Invalid usage")
- Return
-
- :noini
- IniWritePvt(appname, "Maximum Users", 0, inifile)
- IniWritePvt(appname, "Current Users", 0, inifile)
- If IsDefined(handle) == @YES Then FileClose(handle)
- Message("METER Error", "Usage limit for %appname% is unknown")
- If FileExist(inifile) == @FALSE Then Message("METER Error", "Could not create %inifile%")
- Return
-